﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;

namespace Jacobi.ComponentModel.Decomposition.Test.Stubs
{
    /// <summary>
    /// A filter that just outputs the inputs but slowely.
    /// </summary>
    class SlowFilter : FilterBase<PipeData, PipeData>
    {
        private string _name;
        public SlowFilter(string name)
        {
            _name = name;
        }

        protected override IList<PipeData> ProcessInternal(IList<PipeData> inputs)
        {
            Trace.WriteLine(_name, "SlowFilter");

            List<PipeData> outputs = new List<PipeData>(base.Outputs.Count);

            int index = 0;
            foreach (PipeData inData in inputs)
            {
                PipeData outData = new PipeData();

                inData.Buffer.CopyTo(outData.Buffer, 0);

                outputs.Add(outData);

                Thread.SpinWait(10000);

                if (index >= base.Outputs.Count)
                {
                    break;
                }
            }

            return outputs;
        }
    }
}
